package com.gao.shiro.demo.controller;

import com.gao.shiro.demo.pojo.User;
import com.gao.shiro.demo.service.UserService;
import commomresult.CommonResult;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


/**
 * @author gaofeng
 * date 2021年10月10日 16:09
 */
//@ApiOperation("用户相关控制器")
@Controller
public class UserController {

    @Resource
    private UserService userService ;

    @RequiresRoles(logical = Logical.OR, value = {"user", "admin"})
    @PostMapping("/user/getUser")
    @ResponseBody
    public CommonResult<User> getUser(@RequestBody @ApiParam("用户名") @Validated User name) {
        User user = userService.getUser(name.getUsername());
        CommonResult<User> result = new CommonResult<>() ;
        result.setMsg("獲取成功");
        result.setCode("10000");
        result.setData(user);
        return result ;
    }
}
